package utilities.display.shapes;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

import utilities.display.iface.Drawable;


/**
 * 
 * @author CoconutTank
 *
 */
public class DrawLine implements Drawable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -5952001837262369165L;
	
	protected int x1;
	protected int y1;
	protected int x2;
	protected int y2;
	
	protected Color myColor;
	protected Stroke myStyle;
	protected Composite myComposite;
	
	/**
	 * 
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 * @param lineColor
	 * @param stroke
	 * @param lineComposite
	 */
	public DrawLine(int x1, int y1, int x2, int y2, Color lineColor, Stroke stroke, Composite lineComposite)
	{
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		
		myColor = (lineColor == null ? Color.black : lineColor);
		myStyle = (stroke == null ? new BasicStroke() : stroke);
	}

	/**
	 * 
	 */
	public void drawMe(Graphics g) 
	{
		Graphics2D g2 = (Graphics2D) g;
		
		// Get previous settings...
		Color c = g2.getColor();
		Stroke s = g2.getStroke();
		Composite a = g2.getComposite();
		
		// Draw me now!!
		
		// Line portion...
		if(myColor != null && myStyle != null)
		{
			g2.setComposite(myComposite);
			g2.setColor(myColor);
			g2.setStroke(myStyle);
			g2.drawLine(x1, y1, x2, y2);
		}
		
		// Restore previous settings...
		g2.setColor(c);
		g2.setStroke(s);
		g2.setComposite(a);
	}
}
